<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="/struts-tags" prefix="s"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<jsp:include page="/admin/common/css/style_sub.jsp"></jsp:include>
<link rel="stylesheet" type="text/css" href="<%=basePath%>js/lib/validation/css/livevalidation.css"/>
<script type="text/javascript" src="<%=basePath%>js/lib/validation/livevalidation.js"></script>
<script type="text/javascript" src="<%=basePath%>js/lib/jquery/jquery-1.7.1.min.js"></script>
<script type="text/javascript" src="<%=basePath%>js/public.js"></script>
<script language="javascript">
$(function(){
	checkAll();
});

function checkAll(){
	var uname = new LiveValidation('uname',{onlyOnSubmit:true});
	uname.add( Validate.Presence, {failureMessage: "不能为空!"});
	uname.add( Validate.Length, { maximum: 30} );
	uname.add( Validate.Custom, { failureMessage: '登录名已经存在！', against: function(value, args){
		var valid = 'true';
		var params = {
			'user.uname': $('#uname').val(),
			'user.checkUser': 'update',
			'user.id': '${user.id}',
			ct: getCurrentTime()
		};
		
		$.ajaxSetup({async: false});
		$.post('<%=basePath%>basic/sys/user_checkUser.action', params, function(json){
			valid=json.valid;
		});
		return (valid == 'true');
	}});
	
	var rname = new LiveValidation('rname',{onlyOnSubmit:true});
	rname.add( Validate.Presence, {failureMessage: "不能为空!"});
	rname.add( Validate.Length, { maximum: 30} );
	
	var org_name = new LiveValidation('org_name',{onlyOnSubmit:true});
	org_name.add( Validate.Presence, {failureMessage: "不能为空!"});
	
	var uphone = new LiveValidation('uphone',{onlyOnSubmit:true});
	uphone.add( Validate.Presence, {failureMessage: "不能为空!"});
	
	var email = new LiveValidation('email',{onlyOnSubmit:true});
	email.add( Validate.Email, {failureMessage: "邮箱地址不合法!"});
}

function chooseOrgan(){
	var url = '<%=basePath%>admin/basic/system/dep/organ_choose.jsp'; 
	window.callback = fillOrgan;
	openModalWindow(url, window, 'small');
}

function fillOrgan(orgId, orgName){
	$('input[name="user.org_id"]').val(orgId);
	$('input[name="user.org_name"]').val(orgName);
	
	var params = {
		ct: (new Date()).getTime(),
		'pos.org_id': orgId
	};
	$.getJSON("<%=basePath%>basic/sys/orgpos_loadPositionJSON.action", params, function(json){
		if(json.resultCode == 'success'){
			$('#position').empty();
			for(var i=0; i<json.list.length; i++){
				$('#position').append('<option value="' + json.list[i].position_id + '">' + json.list[i].position_name + '</option>');
			}
		}
	});
}

</script>
</head>
<body>
	<div class="title">修改用户</div>
	<form action="<%=basePath %>basic/sys/user_updateUser.action" id="form" method="post">
		<div class="editorTab">
			<table>
				<tbody>
					<tr>
						<th>用户类型</th>
						<td>
							<select name="user.utype" class="downMenu">
								<option value="1" <s:if test="%{user.utype == 1}">selected="selected"</s:if>>内部用户</option>
								<option value="2" <s:if test="%{user.utype == 2}">selected="selected"</s:if>>外部用户</option>
							</select>
						</td>
						<th><font>*</font>登录账号</th>
						<td>
							<input type="text" name="user.uname" id="uname" value="${user.uname}"/>
						</td>
					</tr>
					<tr>
						<th><font>*</font>姓&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;名</th>
						<td>
							<input type="text" name="user.rname" id="rname" value="${user.rname}"/>
						</td>
						<th><font>*</font>性&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;别</th>
						<td>
							<select name="user.gender" class="downMenu">
								<option value="1" <s:if test="%{user.gender == 1}">selected="selected"</s:if>>男</option>
								<option value="2" <s:if test="%{user.gender == 2}">selected="selected"</s:if>>女</option>
							</select>
						</td>
					</tr>
					<tr>
						<th><font>*</font>所在部门</th>
						<td>
							<a href="javascript:void(0);" onclick="chooseOrgan();">
								<input type="text" readonly="readonly" name="user.org_name" id="org_name" value="${user.org_name}" readonly="readonly"/>
								<img src="<%=basePath%>style/images/ico_11.gif" />
							</a>
							<input type="hidden" name="user.org_id" value="${user.org_id}"/>
						</td>
						<th>担任职务</th>
						<td>
							<select name="user.position_id" id="position" class="downMenu">
								<option value="${user.position_id}">${user.position_name}</option>
							</select>
						</td>
					</tr>
					<tr>
						<th><font>*</font>用户手机号</th>
						<td><input type="text" name="user.uphone" id="uphone" value="${user.uphone}"/></td>
						<th>办公电话</th>
						<td><input type="text" name="user.ophone" id="ophone" value="${user.ophone}"/></td>
					</tr>
					<tr>
						<th>用户邮箱</th>
						<td colspan="3"><input type="text" name="user.email" id="email" value="${user.email}"/></td>
					</tr>
				</tbody>
			</table>
		</div>
	
		<div class="infoTips">
			加"<font>*</font>"的为必选或必填项
		</div>
		
		<div class="btns">
			<input type="hidden" name="user.id" value="${user.id}"/>
			<span class="btn"><input type="submit" id="submitBtn" value="提交" /></span>
			<span class="btn">
				<input type="button" id="cancelBtn" value="返回" 
					onclick="javascript:window.location.href='<%=basePath%>basic/sys/user_selectUser.action'"/>
			</span>
		</div>
	</form>
</body>
</html>